package com.yonyou.brigade.order_center.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.order_center.dao.BriTrainPaymentMapper;
import com.yonyou.brigade.order_center.model.BriTrainPassenger;
import com.yonyou.brigade.order_center.dao.BriTrainPassengerMapper;
import com.yonyou.brigade.order_center.model.BriTrainPassengerDTO;
import com.yonyou.brigade.order_center.model.BriTrainPayment;
import com.yonyou.brigade.order_center.service.IBriTrainPassengerService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiangzhf@yonyou.com
 * @since 2018-07-12
 */
@Service
public class BriTrainPassengerServiceImpl extends ServiceImpl<BriTrainPassengerMapper, BriTrainPassenger> implements IBriTrainPassengerService {

    @Autowired
    private BriTrainPassengerMapper briTrainPassengerMapper;

    @Autowired
    private BriTrainPaymentMapper briTrainPaymentMapper;

    @Override
    public Map getBriTrainPassengerDTOs(Map params) {
        Map queryParams=new HashMap();
        queryParams.put("beginOrder",params.get("beginOrder"));
        queryParams.put("endOrder",params.get("endOrder"));
        queryParams.put("beginDeparture",params.get("beginDeparture"));
        queryParams.put("endDeparture",params.get("endDeparture"));
        queryParams.put("createBy",params.get("createBy"));
        queryParams.put("psgName",params.get("psgName"));
        queryParams.put("relateYBZID",params.get("relateYBZID"));
        queryParams.put("fromType",params.get("fromType"));
        queryParams.put("orderStatus",params.get("orderStatus"));
        queryParams.put("payType",params.get("payType"));
        queryParams.put("seatType",params.get("seatType"));
        queryParams.put("orderNo",params.get("orderNo"));
        int pageSize=Integer.parseInt(params.get("pageSize").toString());
        int current=Integer.parseInt(params.get("current").toString());
        if(pageSize<=0)
        {
            pageSize=10;
        }
        if(current<=0)
        {
            current=1;
        }
        int begin=(current-1)*pageSize;
        queryParams.put("begin",begin);
        queryParams.put("pageSize",pageSize);
        Map result=new HashMap();
        try {
            int total=briTrainPassengerMapper.getBriTrainPassengerDTOsCount(queryParams);
            List<BriTrainPassengerDTO> briTrainPassengerDTOs= briTrainPassengerMapper.getBriTrainPassengerDTOs(queryParams);
            List<BriTrainPassengerDTO> briTrainPassengerDTOList=perfectTrainPassengerDTOs(briTrainPassengerDTOs);
            result.put("information",briTrainPassengerDTOList);
            result.put("code","0");
            JSONObject pagination=new JSONObject();
            pagination.put("total",total);
            pagination.put("pageSize",pageSize);
            pagination.put("current",current);
            result.put("pagination",pagination);
        }
        catch (Exception e)
        {
            result.put("code","100");
            result.put("information","操作失败");
            e.printStackTrace();
        }


        return  result;

    }


    private List<BriTrainPassengerDTO> perfectTrainPassengerDTOs(List<BriTrainPassengerDTO> trainPassengerDTOS)
    {
        List<BriTrainPassengerDTO> trainPassengerDTOList=new ArrayList<>();
        if(trainPassengerDTOS==null)
        {
            return  trainPassengerDTOS;
        }
        else
        {
            for(int i=0;i<trainPassengerDTOS.size();i++)
            {
//                trainPassengerDTOList.add(OrderConvert.perfactTrainDTO(trainPassengerDTOS.get(i)));
            }
        }
        return  trainPassengerDTOList;
    }

    @Override
    public List<BriTrainPassenger> getBriTrainPassenger(String orderNo) {
        return briTrainPassengerMapper.getBriTrainPassengerList(orderNo);
    }

    @Override
    public List<BriTrainPayment> getBriTrainPayment(String orderNo) {
        return briTrainPaymentMapper.getBriTrainPaymentList(orderNo);
    }
}
